package 吃蛋糕;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 10010;
    static int[] f = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            int n = in.nextInt();
            Arrays.fill(f, 0x3f3f3f3f);
            f[0] = 0;
            for (int i = 1; i * i <= n; i++) {
                for (int j = i * i; j <= n; j++) {
                    f[j] = Math.min(f[j], f[j - i * i] + 1);
                }
            }
            System.out.printf("Case #%d: %d\n", cases, f[n]);
        }
    }
}
